package com.lc.afbx.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.activity.ApplyJoinActivity;
import com.lc.afbx.activity.BusinessJoinDetailActivity;
import com.lc.afbx.adapters.RuZhuAdapter;
import com.lc.afbx.conn.GetApiShangJiaRuZhu;
import com.lc.afbx.util.PrefrenceConfig;
import com.lc.afbx.widget.MyListView;
import com.zcx.helper.activity.AppV4Fragment;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/18.
 */
public class FragmentBusinessJoinBusiness extends AppV4Fragment implements View.OnClickListener{


    private MyListView fragment_business_join_lv;
    private Button fragment_business_join_submit_bt;

    private RuZhuAdapter adapter;
    private List<GetApiShangJiaRuZhu.Data> dataList = new ArrayList<>();

    private GetApiShangJiaRuZhu getApiShangJiaRuZhu = new GetApiShangJiaRuZhu(new AsyCallBack<GetApiShangJiaRuZhu.Info>() {
        @Override
        public void onSuccess(String toast, int type, GetApiShangJiaRuZhu.Info info) throws Exception {

            fragment_business_join_submit_bt.setVisibility(View.VISIBLE);

            dataList.addAll(info.dataList);

            adapter.notifyDataSetChanged();

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(getActivity(), toast);
        }
    });

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_businessjoin_business, null);
        BaseApplication.ScaleScreenHelper.loadView((ViewGroup) view);

        fragment_business_join_submit_bt = (Button) view.findViewById(R.id.fragment_business_join_submit_bt);

        fragment_business_join_lv = (MyListView) view.findViewById(R.id.fragment_business_join_lv);
        fragment_business_join_lv.setDivider(null);
        fragment_business_join_lv.setAdapter(adapter = new RuZhuAdapter(getActivity(), dataList));

        fragment_business_join_lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(getActivity(), BusinessJoinDetailActivity.class);

                Bundle bundle = new Bundle();
                bundle.putSerializable("data", dataList.get(position));
                intent.putExtras(bundle);

                startActivity(intent);
            }
        });

        //商家入驻接口
        getApiShangJiaRuZhu.tid = PrefrenceConfig.TWO;
        getApiShangJiaRuZhu.userid = BaseApplication.BasePreferences.readUserId();
        getApiShangJiaRuZhu.execute(getActivity());

        fragment_business_join_submit_bt.setOnClickListener(this);

        return view;
    }


    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.fragment_business_join_submit_bt:

                startActivity(new Intent(getActivity(), ApplyJoinActivity.class));

                break;

        }
    }




}
